﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace hse_2013_local_game2d
{
    public class WaterBomb:Bomb
    {
        private int velocity;
        private double uVelocity;
        private Image bombImage;
        private Image explosionImage;
        private double angle;
        private Point[] destinationPoints;
        public WaterBomb(Point position,Image explosionImage, Image bombImage,double angle,int velocity,double uVelocity)
            : base(position,explosionImage)
        {
            this.explosionImage = explosionImage;
            this.bombImage = bombImage;
            this.angle = angle;
            this.velocity = velocity;
            this.uVelocity =uVelocity;
            destinationPoints = new Point[3];
            destinationPoints[0] = position;
            destinationPoints[1] = new Point((int)(position.X + 20*Math.Cos(angle)), (int)(position.Y+20*Math.Sin(angle)));
            destinationPoints[2] = new Point((int)(position.X - 10 * Math.Sin(angle)), (int)(position.Y + 10 * Math.Cos(angle))); //размеры бомбы 20*10
        }

        public override void Move()
        {
            if (!BurnMode)
            {
                bPosition.X = bPosition.X + velocity;
                bPosition.Y = Convert.ToInt32(bPosition.Y + uVelocity);
                if (uVelocity != 0)
                    angle = (Math.Atan(uVelocity / velocity));
                else
                    angle = 0;
                destinationPoints[0] = bPosition;
                destinationPoints[1] = new Point((int)(bPosition.X + 20 * Math.Cos(angle)), (int)(bPosition.Y + 20 * Math.Sin(angle)));
                destinationPoints[2] = new Point((int)(bPosition.X - 10 * Math.Sin(angle)), (int)(bPosition.Y + 10 * Math.Cos(angle)));
                uVelocity = uVelocity + 0.3;
            }
            else
            {
                angle = 0;
                destinationPoints[0] = new Point(bPosition.X - 30, bPosition.Y - 30);
                destinationPoints[1] = new Point((int)(bPosition.X + 20 * Math.Cos(angle) + 30), (int)(bPosition.Y + 20 * Math.Sin(angle) - 30));
                destinationPoints[2] = new Point((int)(bPosition.X - 10 * Math.Sin(angle) - 30), (int)(bPosition.Y + 10 * Math.Cos(angle) + 30));
            }
        }

        public override void OnPaint(Graphics g)
        {
            if (!BurnMode)
            {
                g.DrawImage(bombImage, destinationPoints);
            }
            else
            {
                explosionFrameCounter++;
                g.DrawImage(explosionImage, destinationPoints);
            }
        }
    }
}
